package com.tierstall.client.presenter;

import java.util.ArrayList;

import com.google.gwt.event.shared.HandlerManager;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.HasWidgets;

import com.tierstall.client.event.GoToPageEvent;
import com.tierstall.client.service.WebServices;
import com.tierstall.client.view.content.CV_dbFilter;
import com.tierstall.shared.GruppeDTO;
import com.tierstall.shared.Page;
import com.tierstall.shared.UserDTO;
import com.tierstall.shared.SearchQuery;

public class DBFilterPresenter extends AbstractContentViewPresenter<CV_dbFilter> implements 
		CV_dbFilter.AbstractDBFilterPresenter {



	// private boolean isUpdating = false;

	public DBFilterPresenter(WebServices rpcServices, String session_id,
			HandlerManager eventBus, MainPresenter mainPresenter,
			UserDTO currentUser) {
		super(rpcServices, session_id, eventBus, mainPresenter, currentUser);
		view = (CV_dbFilter) mPresenter.getContentView(Page.DB_FILTER);
		this.view.setPresenter(this);
	}

	public void go(final HasWidgets container) {
		fillFilter();
		mPresenter.setContentView(view);
		// container.clear();
		// container.add(view.asWidget());
	}

	private void fillFilter() {
		rpcService.getRpcTierService().getGroups(sessionId,
				new AsyncCallback<ArrayList<GruppeDTO>>() {

					@Override
					public void onFailure(Throwable caught) {
						// TODO Auto-generated method stub

					}

					@Override
					public void onSuccess(ArrayList<GruppeDTO> result) {
						view.fillComboAK(result);

					}

				});

	}

	@Override
	public void onSearchClicked(SearchQuery query) {
		GoToPageEvent event = new GoToPageEvent(Page.SEARCH_RESULT);
		event.setData(query);
		eventBus.fireEvent(event);
	}

}
